<template>
  <!-- 大客户线索管理->经销商大客户区域经理维护 -->
  <div>
    <!-- 搜索 -->
     <FormPanel  
        ref="formPanel"
        :list="initForm"   
        :cols="3"          
        :labelWidth="120"  
        :isSubmitBtn="false"  
        @formChange="formformChangeHandle"
     />
     <!-- table -->
    <FilterTable   
       ref="table" 
       :columns="columns"   
       :fetchapi="fetchParams" 
       :isSelectColumn="isSelectColumn"
       :params="flterValue" 
       :datakey="'records'"
       :onColumnsChange="columns => this.columns = columns">
      <template slot="controls" >
        <el-button size="small" type="primary"  @click="dealerHandle">选择经销商</el-button>
      </template>
   </FilterTable>
    <!-- 经销商弹窗 -->
  <BaseDialog 
      title="人员选择" 
      width="700px"
      destroyOnClose
      :visible.sync="visiblePersonnel"
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}" >
      <personnel-madal  ref="personnelDialog" @close="closePersonnel" />
   </BaseDialog>
    <!-- 经销商弹窗 -->
  <BaseDialog 
      title="经销商查询" 
      width="700px"
      destroyOnClose
      :visible.sync="visibleDealer"
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}" >
      <dealer-madal  ref="addDialog" @close="closeDealer" />
   </BaseDialog>
   <Drawer  :visible.sync="visibleDrawer"
      title="经销商大客户区域经理维护"
      :width="920"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
    >
      <info-modal  v-model="infoId" @close="infoClose" />
   </Drawer>
   <div class="dialogBottmView">
      <el-button @click="closeDialog">取 消</el-button>
      <el-button @click="saveDialog" type="primary">保 存</el-button>
    </div>
  </div>
</template>
<script>
import personnelMadal from './personnel'
import dealerMadal from './dealerDialog'
import infoModal from '../createClue/info'
import { dictionary } from '@/utils/dictMixin';
import { PHONE_PATTERN } from '@/utils/validate' // 验证
export default {
  name: 'customerAdd',
  mixins: [dictionary],
  components: {
    infoModal,dealerMadal,personnelMadal
  },
  data() {
    return {
      visibleDrawer:false,
      visibleDealer:false,
      visiblePersonnel:false,
      isSelectColumn:false,
      infoId:null,
      initForm:this.initFormFun(),
      flterValue:{},  //参数
      columns:this.creatHeader(),
      fetchParams:null, //ipa 接口
    };
  },
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
  methods: {
       openInit(id){
          console.log(id)
       },
      //搜索数据
      initFormFun(){
        return [{
              type: 'INPUT',
              label: '大客户事业部',
              fieldName: 'field1',
              placeholder: '请输入',
              initialValue: '',
              rules: [{ required: true, message: '必填', trigger: 'blur' }] //验证
            },
            { 
              type: 'INPUT',  
              label: '区域经理代码', 
              fieldName: 'field2',  
              placeholder: '请选择',
              initialValue: '', 
              unitRender: () => {
                      return <el-button slot="append" icon="el-icon-search" onClick={() =>this.personnelHandle()}></el-button>
                },
              rules: [{ required: true, message: '必填', trigger: 'blur' }] //验证
            },
            {
              type: 'INPUT',
              label: '区域经理姓名',
              fieldName: 'field3',
              placeholder: '请输入',
              disabled:true,
              initialValue: ''
            },
            {
              type: 'INPUT',
              label: '性别',
              fieldName: 'field3',
              placeholder: '请输入',
              disabled:true,
              initialValue: ''
            },
            {
              type: 'INPUT',
              label: '手机',
              fieldName: 'field3',
              placeholder: '请输入',
              disabled:true,
              initialValue: ''
            },
            {
              type: 'INPUT',
              label: '身份证号',
              fieldName: 'field3',
              placeholder: '请输入',
              disabled:true,
              initialValue: ''
            },
             { type: 'SELECT',  
             label: '状态', 
             fieldName: 'field6',  
             placeholder: '请选择', 
             initialValue: "", 
             itemList:  this.createDictList('1008'),
             rules: [{ required: true, message: '必填', trigger: 'blur' }] //验证 
             }
        ]
      },
      //搜索获取数据
      formChangeHandle(val){
          this.flterValue=val
          console.log(val)
      },
      //table表头和数据源
      creatHeader(){
         return [
         {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
         },
         {
          title: '操作',
          dataIndex: 'column-action',
          width: 100,
          fixed: 'left',
          render: (props, h) => {
            return (
              <div>
                <el-button size="mini" type="text" onClick={() => this.detailHandle(props.row)}>编辑</el-button>
              </div>
            );
          }
        },
        { title: '公司全称',  dataIndex: 'field0', sorter: true,
           render: props => {    //编码转汉字
            return <span>{this.createDictText(props.row.basedataRelateId, '1611')}</span>;
          }},
        { title: '经销商代码',  dataIndex: 'field1', sorter: true},
        { title: '经销商简称',      dataIndex: 'field2', sorter: true},
        { title: '经销商类型',   dataIndex: 'field3', sorter: true},
        { title: '经销商级别',    dataIndex: 'field4',  sorter: true},
        { title: '事业部',  dataIndex: 'field5',   sorter: true},
        { title: '办事处',  dataIndex: 'field6', sorter: true},
        { title: '省份',  dataIndex: 'field7',   sorter: true },
        { title: '城市',  dataIndex: 'field8',  sorter: true},
        { title: '县区',  dataIndex: 'field9', sorter: true}
        ]
      },
      // 选择人员
      personnelHandle(){
        this.visiblePersonnel=true
      },
      // 选择人员-关闭
      closePersonnel(data){
        //返回数据逻辑自己写
        this.initForm[1].initialValue='编号'
        this.visiblePersonnel=data.visible //关闭弹窗
      },
      // 经销商打开窗口 -传数据
      dealerHandle(){
        this.visibleDealer=true
      },
      // 经销商关闭窗口 -返回数据
      closeDealer(data){
        //返回数据逻辑自己写
        this.visibleDealer=data.visible //关闭弹窗
    },
    //新增、编辑
    detailHandle(row){
      this.infoId=1001  //行id
      this.visibleDrawer=true
    },
    //关闭详情
    infoClose(){
      this.visibleDrawer=false
      if (type === 'refresh') {
        // 重新加载
        this.fetchParams = { ...this.fetchParams };
      }
    },
    //保存
    saveDialog(){
      this.$emit('close', {visible:false,});
    },
    //取消操作
    closeDialog(){
      this.$emit('close', {visible:false,});
    }
  }
};
</script>

<style lang="less" scoped>
</style>
